package com.itheima.controller;


import com.itheima.domain.PmsProductAttribute;
import com.itheima.manager.PmsProductAttributeManager;
import com.itheima.util.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping
public class PmsProductAttributeController {
    @Autowired
    PmsProductAttributeManager pmsProductAttributeManager;


    /**
     * 根据分类查询属性列表或参数列表
     * @param cid
     * @param pageNum
     * @param pageSize
     * @param type
     * @return
     */
    @GetMapping("/productAttribute/list/{cid}")
    public R findAttributeByPage(
            @PathVariable(value = "cid")Integer cid,
            @RequestParam(defaultValue = "1")Integer pageNum,
            @RequestParam(defaultValue = "5")Integer pageSize,
            @RequestParam(value = "type")String type
    ){
      return pmsProductAttributeManager.findAttributeByPage(cid,pageNum,pageSize,type);
    }

    /**
     * 根据商品分类的id获取商品属性及属性分类
     * @param productCategoryId
     * @return
     */
    @GetMapping("/productAttribute/attrInfo/{productCategoryId}")
    public R findAttributeById(@PathVariable Long productCategoryId){
        return pmsProductAttributeManager.findAttributeById(productCategoryId);
    }

    /**
     * 添加属性信息
     * @param productAttributeParam
     * @return
     */
    @PostMapping("/productAttribute/create")
    public R addAttribute(@RequestBody PmsProductAttribute productAttributeParam){
        return pmsProductAttributeManager.addAttribute(productAttributeParam);
    }


    /**
     * 批量删除商品属性
     * @param ids
     * @return
     */
    @PostMapping("/productAttribute/delete")
    public R deleteByIds(@RequestParam List<Long> ids){
        return pmsProductAttributeManager.deleteByIds(ids);
    }

    /**
     * 修改商品属性信息
     * @param id
     * @param productAttributeParam
     * @return
     */
    @PostMapping("/productAttribute/update/{id}")
    public R updateById(@PathVariable Long id,@RequestBody PmsProductAttribute productAttributeParam){
        return pmsProductAttributeManager.updateById(id,productAttributeParam);
    }


    /**
     * 查询单个商品属性
     * @param id
     * @return
     */
    @GetMapping("/productAttribute/{id}")
    public R findById(@PathVariable Long id){
        return pmsProductAttributeManager.findById(id);
    }



}
